package com.dcoinpay.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.dcoinpay.common.exception.BusinessException;
import com.dcoinpay.sys.mapper.GeneratorMapper;
import com.dcoinpay.sys.mapper.SysGeneratorMysqlMapper;

/**
 * 数据库配置
 *
 * @author wenbin
 * @version V1.0
 * @date 2020年3月18日
 */
@Configuration
public class DbConfig {
	@Value("${project.database}")
	private String database;
	@Autowired
	private SysGeneratorMysqlMapper sysGeneratorMysqlMapper;

	@Bean
	@Primary
	public GeneratorMapper getGeneratorMapper() {
		if ("mysql".equalsIgnoreCase(database)) {
			return sysGeneratorMysqlMapper;
		} else {
			throw new BusinessException("不支持当前数据库：" + database);
		}
	}
}
